<template>
	<!-- 	<view>
		<view class="bg">
			<view class="display-a">
				<view class="name">{{obj.cardType == 1 ? '折扣券' : obj.cardType == 2 ? '满减券' : obj.cardType == 3 ? '礼品券' : '红包券'}}</view>
				<view style="margin-left: 56rpx;">
					<view class="font-size_32rpx font-weight_bold margin-bottom_20rpx">{{obj.cardType == 1 ? '折扣券' : obj.cardType == 2 ? '满减券' : obj.cardType == 3 ? '礼品券' : '红包券'}}</view>
					<view class="color_999999 font-size_26rpx">核销有效期 {{obj.checkEndTime}}</view>
				</view>
			</view>
			<image class="img-31" @click="getCollectCardCoupons()" src="../../static/31.png"></image>
		</view>
	</view> -->


	<view class="receiveCoupon">
		<view class="display-a">
			<!-- 1折扣券，2满减券,3礼品券,4红包券 -->
			<view class="name">
				{{activityDetailInfo.cardType == 1 ? '折扣券' : activityDetailInfo.cardType == 2 ? '满减券' :activityDetailInfo.cardType == 3 ? '礼品券' : '红包券'}}
			</view>
			<view style="margin-left: 56rpx;">
				<view class="font-size_32rpx font-weight_bold margin-bottom_20rpx">
					{{activityDetailInfo.cardType == 1 ? '折扣券' : activityDetailInfo.cardType== 2 ? '满减券' : activityDetailInfo.cardType == 3 ? '礼品券' : '红包券'}}
				</view>
				<view class="color_999999 font-size_26rpx">核销有效期 {{activityDetailInfo.checkEndTime}}</view>
			</view>
		</view>
		
		<view class="img-102">
			<scroll-view :scroll-y="true" class="detail">{{activityDescription}}</scroll-view>
		</view>
		
		<view style="height: 150rpx;"></view>
		
		<image class="img-103" @click="getCollectCardCoupons" src="../../static/103.png"></image>
		
		
		<view class="pos-right" @click="myAwardGo">我的奖品</view>
		
		<view class="pos-left" v-if="user.id">
			<image class="head" :src="user.head"></image>
			<view class="pos-name font-overflow">{{user.nickname}}</view>
			<view v-if="releaseChannel == 1" class="pos-but" @click="getOpenHomepage()">关注</view>
		</view>
		
		<!-- <image class="img-31" @click="getCollectCardCoupons" src="../../static/31.png"></image>

		<view class="myAward " @click="myAwardGo()">我的奖品</view> -->

	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				uid: '',
				c_type: '',
				// 活动详情页面
				activityDetailInfo: {},
				
				releaseChannel: '', // 1抖音 3快手
				activityDescription: '',
				
				merchantId: '', //商家ID
				
				user: {},
			}
		},

		onLoad(options) {
			
			if (options.uid) {
				this.uid = options.uid;
			}
			
			if (options.id) {
				this.id = options.id;
				this.detail();
			}
			
			if (options.c_type) {
				this.c_type = options.c_type;
			}
			
		},
		onShow() {
			this.$at.releaseKey('submit');
			this.$at.releaseKey('receiveKey');
		},
		methods: {
			
			//活动详情
			async detail() {
				const result = await this.$http.get({
					url: this.$api.selectGetId,
					data: {
						id: this.id,
					}
				});
				if (result.code == 2000) {
					this.activityDetailInfo = result.data.cardsettings;
					this.releaseChannel = result.data.releaseChannel;
					this.activityDescription = result.data.activityDescription;
					this.merchantId = result.data.merchantId;
					this.dUser();
				} else {
					this.$sun.toast(result.msg, 'none');
				}
			},
			
			//抖音跳转商家主页
			async getOpenHomepage() {
				const result = await this.$http.get({
					url: this.$api.getUserProfile,
					data: {
						openId: this.user.openId,
					}
				});
				if (result.code == 2000) {
					window.location.href = result.data.data.schema;
				} else {
					this.$sun.toast(result.msg, 'none');
				}
				
			},
			
			//抖音、快手用户数据
			async dUser() {
				const result = await this.$http.get({
					url: this.$api.selectMerchantFollowMe,
					data: {
						merchantId: this.merchantId,
					}
				});
				if (result.code == 2000) {
					this.user = result.data;
				} else {
					this.$sun.toast(result.msg, 'none');
				}
			},
			
			// 跳转到我的页面
			myAwardGo() {
				uni.navigateTo({
					url: '/pages/index/myPrize?id='+this.id+'&uid='+this.uid+'&releaseChannel='+this.releaseChannel
				})
			},
			
			// 点击领取卡卷 
			getCollectCardCoupons() {
				this.$at.uniDoFunc({
					// 键名
					key: 'receiveKey',
					success: async () => {
						this.$at.lockKey('receiveKey');
						const result = await this.$http.post({
							url: this.$api.collectCardCoupons,
							data: {
								shopCodeId: this.id,
								uId: this.uid,
							}
						});
						if (result.code == 2000) {
							this.$at.releaseKey('receiveKey');
							uni.showModal({
								title: '提示',
								content: '领取成功',
								success: async (res) => {
									if (res.confirm) {
										if (this.releaseChannel == 1) {
											setTimeout(() => {
												this.sendVideo(result.data)
											}, 1000)
										}
										if (this.releaseChannel == 3) {
											setTimeout(() => {
												this.getForward(result.data)
											}, 1000)
										}
									} else if (res.cancel) {
										this.$sun.toast('请到我的奖品里手动激活','none');
									}
								}
							});
						}else {
							this.$at.releaseKey('receiveKey');
							this.$sun.toast(result.msg,'none')
						}
					}
				})
			},
			
			//转发快手视频
			async getForward(winningId) {
				uni.showLoading({
					title: '转发视频中..'
				})
				const result = await this.$http.get({
					url: this.$api.videoForwarding,
					data: {
						shopId: this.id,
						uid: this.uid,
						winningId: winningId
					}
				});
				if (result.code == 2000) {
					uni.hideLoading()
					uni.showModal({
						title: '提示',
						content: result.msg,
						showCancel: false,
						success: res => {
							uni.navigateBack();
						}
					});
				} else {
					uni.hideLoading()
					this.$sun.toast(result.msg, 'none');
				}
			},
			
			// 转发抖音视频
			async sendVideo(winningId) {
				uni.showLoading({
					title: '转发视频中..'
				})
				const result = await this.$http.get({
					url: this.$api.getShare,
					data: {
						uid: this.uid ,
						shopId: this.id,
						winningId: winningId
					}
				});
				if (result.code == 2000) {
					uni.hideLoading()
					this.jump(result.data);
				} else {
					uni.hideLoading()
					this.$sun.toast('发布失败请重新发布','none');
				}
			},
			// 转发视频进行卡卷的激活
			jump(dyShares) {
				/*
				 * video_path:视频url
				 * image_path:图片url
				 * share_to_publish ? 0 默认(跳转视频编辑页) : 1（跳转视频发行页）
				 * hashTags 转发视频 话题
				 * s_type 挂载类型 1 抖音POI（地址） 2小程序 3 没有
				 *  app_id 小程序id
				 *  app_title 小程序标题
				 *  app_url 小程序地址
				 *  poi_id POI地址
				 */
				// const hashTags = [dyShares.hashtag_list];
				const url = new URL('snssdk1128://openplatform/share');
				var query = url.searchParams;
				query.append('hashtag_list', JSON.stringify(dyShares.hashtag_list));
				query.append('client_key', dyShares.client_key);
				query.append('state', dyShares.state);
				query.append('nonce_str', dyShares.nonce_str);
				query.append('timestamp', dyShares.timestamp);
				query.append('signature', dyShares.signature);
				query.append('share_type', dyShares.share_type);
				query.append('video_path', dyShares.video_path);
				query.append('title', dyShares.tilte);
				if (dyShares.poi_id) {
					query.append('poi_id', dyShares.poi_id);
				}
				// query.append("image_path", "https://sf3-cdn-tos.douyinstatic.com/obj/douyin-open-static/tiktok.open/home/d_logo.png")
				query.append('share_to_publish', dyShares.share_to_publish);
				if (dyShares.mountType == 2) {
					query.append(
						'micro_app_info',
						JSON.stringify({
							appId: dyShares.app_id,
							appTitle: dyShares.app_title,
							appUrl: dyShares.app_url
						})
					);
				}
				window.location.href = url;
			},
		}
	}
	
</script>

<style lang="scss">
	
	.pos-right {
		width: 150rpx;
		text-align: center;
		background: rgba(0, 0, 0, 0.40);
		border-radius: 200rpx 0px 0px 200rpx;
		color: #FFFFFF;
		position: fixed;
		top: 40rpx;
		right: 0;
		z-index: 99;
		padding: 10rpx 0;
	}
	
	.pos-but {
		width: 80rpx;
		border-radius: 36rpx;
		background-color: #FFBC00;
		color: #FFFFFF;
		font-size: 24rpx;
		text-align: center;
		padding: 10rpx;
	}
	
	.pos-name {
		width: 160rpx;
		color: #FFFFFF;
	}
	
	.head {
		width: 64rpx;
		height: 64rpx;
		border-radius: 50%;
		background-color: #aaaaaa;
		margin-right: 14rpx;
	}
	
	.pos-left {
		width: 320rpx;
		background: rgba(0, 0, 0, 0.40);
		border-radius: 60rpx;
		z-index: 99;
		position: fixed;
		top: 40rpx;
		left: 20rpx;
		display: flex;
		align-items: center;
	}
	
	.detail {
		padding: 170rpx 40rpx 20rpx 40rpx;
		height: 320rpx;
		width: 600rpx;
	}
	
	.img-103 {
		width: 510rpx;
		height: 108rpx;
		position: fixed;
		bottom: 40rpx;
		left: 120rpx;
		z-index: 99;
	}
	
	.img-102 {
		width: 674rpx;
		height: 534rpx;
		background: url('~static/102.png');
		background-repeat: no-repeat;
		background-size: contain;
		margin: 120rpx 38rpx 30rpx 38rpx;
	}
	
	.img-31 {
		width: 578rpx;
		height: 136rpx;
		margin: 198rpx 86rpx 0;
	}

	.img-5 {
		width: 578rpx;
		height: 136rpx;
		margin: 50rpx 86rpx 0;
	}

	.myAward {
		text-align: center;
		line-height: 64rpx;
		position: absolute;
		width: 152rpx;
		height: 64rpx;
		border-radius: 200rpx 0rpx 0rpx 200rpx;
		background: rgba(0, 0, 0, 0.50);
		top: 44rpx;
		right: 0;
		color: #fff;
		font-size: 28rpx;
	}

	.name {
		width: 24rpx;
		text-align: center;
		color: #FFFFFF;
		font-size: 24rpx;
		margin-left: 166rpx;
	}

	.receiveCoupon {
		width: 750rpx;
		height: 1662rpx;
		background: url('~static/101.png');
		background-repeat: no-repeat;
		background-size: contain;
		padding: 690rpx 0 0 0;
	}

	page {
		border-top: 0;
		background-color: #F7AD1B;
	}
</style>